package com.cctc.security.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.cctc.framework.bean.BaseObj;
import com.cctc.security.util.SqlUtil;


@Entity
@Table(name = "CCTCT_GROUPS")
public class Group extends BaseObj {
	
	private static final long serialVersionUID = -3040763870712763757L;
	
	@Id
    @Column(length=36,nullable=false)
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = SqlUtil.HIBERNATE_UUID)
	private String id;

	@Column(name = "NAME", length = 30, nullable = false, unique = true)
	private String name;


	@Column(name = "ENABLE", nullable = false)
	private int enabled;

	@Column(name = "IS_SYS", nullable = false)
	private int isSys;

	//mappedBy="listGroups",
	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "CCTCT_USERS_GROUPS",joinColumns={@JoinColumn(name="GROUP_ID")},inverseJoinColumns={@JoinColumn(name="USER_ID")})
	private List<User> listUsers = new ArrayList<User>();
	
	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "CCTCT_GROUPS_AUTHORITIES",joinColumns={@JoinColumn(name="GROUP_ID")},inverseJoinColumns={@JoinColumn(name="AUTHORITIE_ID")})
	private List<Authoritie> listAuthorities = new ArrayList<Authoritie>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getEnabled() {
		return enabled;
	}

	public void setEnabled(int enabled) {
		this.enabled = enabled;
	}

	public int getIsSys() {
		return isSys;
	}

	public void setIsSys(int isSys) {
		this.isSys = isSys;
	}

	public List<User> getListUsers() {
		return listUsers;
	}

	public void setListUsers(List<User> listUsers) {
		this.listUsers = listUsers;
	}

	public List<Authoritie> getListAuthorities() {
		return listAuthorities;
	}

	public void setListAuthorities(List<Authoritie> listAuthorities) {
		this.listAuthorities = listAuthorities;
	}
	
}
